const fs = require('fs');
const path = require('path');
const base = path.join(__dirname, 'data');
const base2 = path.join(__dirname, 'data2');
const avi = Uint8Array.from(fs.readFileSync(path.join(base, 'video-1s.avi')));
const mp4 = Uint8Array.from(fs.readFileSync(path.join(base2, 'video-1s.mp4')));
const wav = Uint8Array.from(fs.readFileSync(path.join(base, 'audio-1s.wav')));
const arial = Uint8Array.from(fs.readFileSync(path.join(base, 'arial.ttf')));
const png = Uint8Array.from(fs.readFileSync(path.join(base, 'image.png')));
const srt = `
1
00:00:00,000 --> 00:00:01,000
ffmpeg.wasm test
`;
const ass = `
[Script Info]
; Script generated by FFmpeg/Lavc58.91.100
ScriptType: v4.00+
PlayResX: 240
PlayResY: 256
ScaledBorderAndShadow: yes

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:01.00,Default,,0,0,0,,ffmpeg.wasm test
`;

const CASES = [
  {
    name: 'wav to aac',
    args: ['-i', 'audio.wav', '-c:a', 'libfdk_aac','audio.aac'],
    input: [
      { name: 'audio.wav', data: wav },
    ],
    output: [
      { name: 'audio.aac', type: 'audio/aac' },
    ]
  },
  {
    name: 'wav to flac',
    args: ['-i', 'audio.wav', 'audio.flac'],
    input: [
      { name: 'audio.wav', data: wav },
    ],
    output: [
      { name: 'audio.flac', type: 'audio/x-flac' },
    ]
  },
  {
    name: 'avi to x264 mp4 with drawtext',
    args: ['-i', 'video.avi', '-vf', 'drawtext=fontfile=/arial.ttf:text=\'Artist\':fontcolor=white:fontsize=24:x=(w-text_w)/2:y=(h-text_h)/2', 'video.mp4'],
    input: [
      { name: 'video.avi', data: avi },
      { name: 'arial.ttf', data: arial },
    ],
    output: [
      { name: 'video.mp4', type: 'video/mp4' },
    ]
  },
  {
    name: 'avi to gif',
    args: ['-i', 'video.avi', '-f', 'gif', 'video.gif'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.gif', type: 'image/gif' },
    ]
  },
  {
    name: 'wav to mp3',
    args: ['-i', 'audio.wav', 'audio.mp3'],
    input: [
      { name: 'audio.wav', data: wav },
    ],
    output: [
      { name: 'audio.mp3', type: 'audio/mpeg' },
    ]
  },
  {
    name: 'avi to x264 mp4 with srt',
    args: ['-i', 'video.avi', '-vf', 'subtitles=test.srt:fontsdir=/fonts:force_style="Fontname=Arial"', 'video.mp4'],
    dirs: ['fonts'],
    input: [
      { name: 'video.avi', data: avi },
      { name: '/fonts/arial.ttf', data: arial },
      { name: 'test.srt', data: srt },
    ],
    output: [
      { name: 'video.mp4', type: 'video/mp4' },
    ]
  },
  {
    name: 'avi to x264 mp4 with ass',
    args: ['-i', 'video.avi', '-vf', 'ass=test.ass:fontsdir=/fonts', 'video.mp4'],
    dirs: ['fonts'],
    input: [
      { name: 'video.avi', data: avi },
      { name: '/fonts/arial.ttf', data: arial },
      { name: 'test.ass', data: ass },
    ],
    output: [
      { name: 'video.mp4', type: 'video/mp4' },
    ]
  },
  {
    name: 'avi to vp9 webm',
    args: ['-i', 'video.avi', '-codec:v', 'libvpx', 'video.webm'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.webm', type: 'video/webm' },
    ]
  },
  {
    name: 'avi to vp9 webm with mt',
    args: ['-i', 'video.avi', '-row-mt', '1', '-codec:v', 'libvpx', 'video.webm'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.webm', type: 'video/webm' },
    ]
  },
  {
    name: 'png to webp',
    args: ['-i', 'image.png', 'image.webp'],
    input: [
      { name: 'image.png', data: png },
    ],
    output: [
      { name: 'image.webp', type: 'image/webp' },
    ]
  },
  {
    name: 'avi to mpeg1',
    args: ['-i', 'video.avi', '-c:v', 'mpeg1video', 'video.mpeg'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.mpeg', type: 'video/MP1S' },
    ]
  },
  {
    name: 'avi to mpeg2',
    args: ['-i', 'video.avi', '-c:v', 'mpeg2video', 'video.mpg'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.mpg', type: 'video/MP1S' },
    ]
  },
  {
    name: 'wav to opus',
    args: ['-i', 'audio.wav', 'audio.opus'],
    input: [
      { name: 'audio.wav', data: wav },
    ],
    output: [
      { name: 'audio.opus', type: 'audio/opus' },
    ]
  },
  {
    name: 'avi to ogv',
    args: ['-i', 'video.avi', '-c:v', 'libtheora', 'video.ogv'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.ogv', type: 'video/ogg' },
    ]
  },
  {
    name: 'wav to ogg',
    args: ['-i', 'audio.wav', '-c:a', 'libvorbis', 'audio.ogg'],
    input: [
      { name: 'audio.wav', data: wav },
    ],
    output: [
      { name: 'audio.ogg', type: 'audio/ogg' },
    ]
  },
  {
    name: 'wav to wv',
    args: ['-i', 'audio.wav', 'audio.wv'],
    input: [
      { name: 'audio.wav', data: wav },
    ],
    output: [
      { name: 'audio.wv', type: 'audio/wavpack' },
    ]
  },
  {
    name: 'avi to x264 mp4',
    args: ['-i', 'video.avi', 'video.mp4'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.mp4', type: 'video/mp4' },
    ]
  },
  // It takes too much time for single thread version to
  // transcode x265, thus skip.
  {
    name: 'avi to x265 10bit mp4',
    args: ['-i', 'video.avi', '-c:v', 'libx265', '-pix_fmt', 'yuv420p10le', 'video.mp4'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.mp4', type: 'video/mp4' },
    ],
    st: false,
  },
  {
    name: 'avi to x265 12bit mp4',
    args: ['-i', 'video.avi', '-c:v', 'libx265', '-pix_fmt', 'yuv420p12le', 'video.mp4'],
    input: [
      { name: 'video.avi', data: avi },
    ],
    output: [
      { name: 'video.mp4', type: 'video/mp4' },
    ],
    st: false,
  },
  {
    name: 'mp4 scale',
    args: ['-i', 'video.mp4', '-vf', 'scale=128:-1', 'video-scaled.mp4'],
    input: [
      { name: 'video.mp4', data: mp4 },
    ],
    output: [
      { name: 'video-scaled.mp4', type: 'video/mp4' },
    ]
  },
  {
    name: 'png to mp4',
    args: ['-i', 'image.png', 'video.mp4'],
    input: [
      { name: 'image.png', data: png },
    ],
    output: [
      { name: 'video.mp4', type: 'video/mp4' },
    ]
  },
  {
    name: 'png to webm',
    args: ['-i', 'image.png', 'video.webm'],
    input: [
      { name: 'image.png', data: png },
    ],
    output: [
      { name: 'video.webm', type: 'video/webm' },
    ]
  },
];

module.exports = {
  TIMEOUT: 300000,
  CASES,
};
